//-----------------------------------------------------------------------
// <copyright file="BulkOrder.cs" company="Pyramid Consulting">
//     Copyright (c) Pyramid Consulting. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
	
using System;
using System.Data;
using System.ComponentModel;
using System.Collections;

namespace MIMS.WRS.Entities
{
	[Serializable]
	public class BulkOrder : BulkOrderBase
	{
		public BulkOrder()
		{
			InitValues();
		}

		private string _IDSSort = string.Empty;
		public string IDSSort 
		{
			get { return _IDSSort; }
			set { _IDSSort = value; }
		}

		private string currencyCode = string.Empty;
		public string CurrencyCode 
		{
			get { return currencyCode; }
			set { currencyCode = value; }
		}
		

		private string catalogName = string.Empty;
		public string CatalogName 
		{
			get { return catalogName; }
			set { catalogName = value; }
		}

		private int notStarted;
		public int NotStarted 
		{
			get { return notStarted; }
			set { notStarted = value; }
		}

		private int quantityAvailable;
		private int quantityReserved;
		//private int adjustedQuantity;
		public int QuantityAvailable 
		{
			get { return quantityAvailable; }
			set { quantityAvailable = value; }
		}

		public int QuantityReserved 
		{
			get { return quantityReserved; }
			set { quantityReserved = value; }
		}

		//		public int AdjustedQuantity 
		//		{
		//			get { return adjustedQuantity; }
		//			set { adjustedQuantity = value; }
		//		}

		public int TotalQtyNotStarted 
		{
			get 
			{
				int completed = TotalQtyCompleted==Nulls.NullInteger?0:TotalQtyCompleted;
				int a50 = TotalQtyInProgressAbove50P==Nulls.NullInteger?0:TotalQtyInProgressAbove50P;
				int b50 = TotalQtyInProgressBelow50P==Nulls.NullInteger?0:TotalQtyInProgressBelow50P;
				return this.TotalQtyOrdered - (completed + a50 + b50);					
			}
		}

		private void InitValues() 
		{
			// init nulls values			
			this.CompletedDate = Nulls.NullDate;			
			this.EstimatedDate = Nulls.NullDate;
			this.FOB = Nulls.NullDecimal;
			this.StartDate = Nulls.NullDate;
			this.StockLastCheckedDate = Nulls.NullDate;
			this.StockLastCheckedQty = Nulls.NullInteger;
			this.TotalQtyCompleted = Nulls.NullInteger;
			this.TotalQtyInProgressAbove50P  = Nulls.NullInteger;
			this.TotalQtyInProgressBelow50P = Nulls.NullInteger;	
			this.PackQty = Nulls.NullInteger;
			this.CatalogID = Nulls.NullInteger;						
			this.IDSSortID = Nulls.NullInteger;
			this.MUKTHGCatPackQty = Nulls.NullInteger;
			this.HomeDelivered15Price = Nulls.NullDecimal;
			this.CurrencyID = Nulls.NullInteger;
			this.SpecialOfferDisc = Nulls.NullDecimal;
			this.ModifiedDate = Nulls.NullDate;
			this.QtyUnitsPer40Cont = Nulls.NullInteger;	
			this.QtyUnitsPer20Cont = Nulls.NullInteger;	
			this.UnitWeight =Nulls.NullDecimal;
			this.HCC_Code = string.Empty;
			this.QuantityAvailable = Nulls.NullInteger;	
		}

		public static int GetQuantityAvailableCatalog(int qtyAvail, int packQty) 
		{
			if (qtyAvail != Nulls.NullInteger && packQty != Nulls.NullInteger)
				return (int)Math.Floor((double)qtyAvail / (double)packQty);
			else
				return Nulls.NullInteger;
		}

		public static int CalcQtyAvailMUKTHGCatalogPack(int qtyAvailUnits, int MUKTHGCatPackQty) 
		{
			return (int)Math.Floor((double)qtyAvailUnits / (double)MUKTHGCatPackQty);
		}

		public int IDSQuantityAvail 
		{
			get 
			{
				if (this.IsShownInLGDCatalog == true) 
				{
					//return this.PackQty;					
					return BulkOrder.GetQuantityAvailableCatalog(this.QuantityAvailable, this.PackQty);
				}
				else 
				{
					return this.QuantityAvailable;
				}				
			}
		}

		public string IDSQuantityAvailDesc
		{
			get 
			{
				if (this.IsShownInLGDCatalog == true) 
				{
					if (this.PackQty != Nulls.NullInteger) 
						return GetBOPackType2Meaning(this.CatPackDesc);		
					else
						return "";
				}
				else 
				{
					if (this.QuantityAvailable != Nulls.NullInteger) 
					{
						return GetBOPackTypeMeaning(this.Pack);
					}
					else
						return "";
				}				
			}
		}
	
		const string MIXED_TALL_PALLET = "Mixed Tall Pallet";
		const string MIXED_HALF_PALLET = "Mixed Half Pallet";
		const string MIXED_TALL_PALLET_CODE = "4AMP";
		const string MIXED_HALF_PALLET_CODE = "4MHP";
		const string HALF_PALLET = "Half Pallet";

		public static string GetBOPackTypeMeaning(string _value) 
		{			
			switch (_value.ToUpper()) 
			{
				case "1PIE":
					return "Pieces";
				case "2SET":
					return "Sets";
				case "2UNT":
					return "Units";
				case "3OUT":
					return "Outers";

				case MIXED_TALL_PALLET_CODE: //Mixed Tall Pallet
					return MIXED_TALL_PALLET;

				case MIXED_HALF_PALLET_CODE: //Mixed Half Pallet
					return MIXED_HALF_PALLET;

				case "4HDP":
					return HALF_PALLET; //Half Pallet

				case "5TSP":
					return "TS Pallet"; //Tall Pallet

				case "6TDP":
					return "TD Pallet";//Half Pallet

				case "7SDP":
					return "SD Pallet";//Half Pallet

				case "8HCC":
					return "Half Crate";
				default:
					return _value.ToString();
			}
		}
																		

		public static string GetBOPackType2Meaning(string _value)
		{
			switch (_value.ToUpper()) 
			{
				case "1PIE":
					return "Pieces";
				case "2SET":
					return "Sets";
				case "2UNT":
					return "Units";
				case "3OUT":
					return "Outers";

				case MIXED_TALL_PALLET_CODE: //Mixed Tall Pallet
					return MIXED_TALL_PALLET;

				case MIXED_HALF_PALLET_CODE: //Mixed Half Pallet
					return MIXED_HALF_PALLET;

				case "4HDP":
					return HALF_PALLET;

				case "5TSP":
					return "Tall Pallets";  

				case "8HCC":
					return "Half Crate";

				case "6CRA":
					return "Crate -A"; 
				case "6CRB":
					return "Crate -B";
				case "6CRC":
					return "Crate -C";
				case "6CRD":
					return "Crate -D";
				case "6CRE":
					return "Crate -E";
				default:
					return _value.ToString();
			}
		}

		public static string GetBOTypeCode(byte code)
		{
			switch (code) 
			{
				case 1:
					return "OD";  // Ordered
				case 2:
					return "SC"; // Stock Clear
				case 3:
					return "SF"; // Stock Fact
				default:
					return "";
			}
		}

		public static string GetOwnerCode(int ownerID)
		{
			if (ownerID == 9999)
				return "S";
			else
				return ownerID.ToString();			
		}

		public string TypeCode
		{
			get 
			{
				if (this.Type > 0) 
				{
					return GetBOTypeCode(this.Type);		
				}
				else 
				{
					return "";
				}				
			}
		}

		public string OwnerCode
		{
			get 
			{				
					return GetOwnerCode(this.Owner);									
			}
		}
		
						//		public int QuantityAvailableCatalog
						//		{
						//			get { return GetQuantityAvailableCatalog(QuantityAvailable, PackQty); }			
						//		}
					}
}